#include<stdio.h>
#include<stdlib.h> //exit()
#include<unistd.h> //sleep() fork()
#include<sys/wait.h>

int main()
{
  pid_t pid = fork(); //创建一个子进程
  if(pid<0){
    perror("fork error");
    return -1;
  }else if(pid == 0){
    sleep(3);
    exit(99);
  }
  
  printf("wait start ----------\n");
  int status;
  while(waitpid(-1,&status,WNOHANG) == 0){
    printf("have child ,have not exited ,waiting...\n");
    sleep(1);
  }
  if (( status&0x7f) == 0){
    printf("child exit code:%d\n",(status>>8) & 0xff);
  }else{
    printf("signal code:%d\n",status & 0x7f );
  }
  printf("wait end ----------\n");
}
